package org.example.demo;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.concurrent.atomic.AtomicInteger;

public class FrameFractory {
    private static final AtomicInteger FRAME_COUNT = new AtomicInteger(0);

    private FrameFractory() {
    }

    public static Frame createFrame(int width,int height,int locX,int locY,Color color){
        Frame frame = new Frame("我的窗口" + FRAME_COUNT.getAndIncrement());
        frame.setBackground(color);
        frame.setLocation(locX,locY);
        frame.setSize(width,height);
        frame.setVisible(true);
        return frame;
    }

    public static Frame createFrameAllowClose(){
        Frame frame = new Frame();
        frame.setVisible(true);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        return frame;
    }

    public static JDialog createJDialog(){
        JDialog jDialog = new JDialog();
        jDialog.setVisible(true);
        jDialog.setBounds(100,100,200,200);
        return jDialog;
    }

    public static JFrame createJFrameDefault(){
        JFrame jFrame = new JFrame();
        jFrame.setVisible(true);
        jFrame.setBounds(100,100,600,600);
        jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        return jFrame;
    }
}
